package Zoo.view.leaderview;

import Zoo.entity.ZoomenEntity;
import Zoo.handler.UpdateZoomenViewHandler;

import javax.swing.*;
import java.awt.*;

/**
 * 1、UpdateZoomenView用于园长修改动物饲养员信息
 */
public class UpdateZoomenView extends JDialog {
    JPanel jPanel = new JPanel();
    JLabel idLable = new JLabel("修改对象的id");
    JTextField idTxt = new JTextField();
    JLabel idNumberLable = new JLabel("身份证号");
    JTextField idNumberTxt = new JTextField();
    JLabel phoneLable = new JLabel("联系电话");
    JTextField phoneTxt = new JTextField();
    JLabel nameLable = new JLabel("姓名");
    JTextField nameTxt = new JTextField();
    JButton updateBtn = new JButton("修改");

    UpdateZoomenViewHandler updateZoomenViewHandler;

    public UpdateZoomenView(LeaderView1 leaderView1) {
        super(leaderView1, "修改动物饲养员信息", true);

        updateZoomenViewHandler = new UpdateZoomenViewHandler(this, leaderView1);

        idLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(idLable);
        idTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(idTxt);


        idNumberLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(idNumberLable);
        idNumberTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(idNumberTxt);

        phoneLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(phoneLable);
        phoneTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(phoneTxt);

        nameLable.setPreferredSize(new Dimension(80, 30));
        jPanel.add(nameLable);
        nameTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(nameTxt);


        Container contentPane = getContentPane();
        contentPane.add(jPanel);
        //监听
        updateBtn.addActionListener(updateZoomenViewHandler);
        jPanel.add(updateBtn);

        setSize(350, 500);
        setLocationRelativeTo(null);
        //DISPOSE_ON_CLOSE：只销毁当前的窗体
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);


    }

    //获取修改后的动物饲养员信息
    public ZoomenEntity buildUpdatedZoomenEntity() {
        ZoomenEntity zoomenEntity = new ZoomenEntity();
        zoomenEntity.setId(Integer.valueOf(idTxt.getText()));
        zoomenEntity.setIdNumeber(idNumberTxt.getText());
        zoomenEntity.setPhone(phoneTxt.getText());
        zoomenEntity.setZoomenName(nameTxt.getText());
        return zoomenEntity;
    }
}
